package com.c3p0;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class C3P0Test1 {
    public static void main(String[] args) throws SQLException {
        //创c3p0连接池对象
        DataSource dataSource = new ComboPooledDataSource();
        //获取数据库连接进行使用
        Connection con = dataSource.getConnection();
        //查询学生全部信息
        String sql ="select * from student";
        PreparedStatement pst = con.prepareStatement(sql);
        ResultSet rs = pst.executeQuery();
        while(rs.next()){
            System.out.println(rs.getInt("sid")+"\t"+rs.getString("name")+"\t"+rs.getInt("age")+"\t"+rs.getString("birthday"));
        }
        rs.close();
        pst.close();
        //这一行是归还连接
        con.close();
    }
}
